﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Text;
using Microsoft.SqlServer.Management.Smo;

namespace SQL_EG
{
   public class EntityProperty
    {
        public string Name { get; set; }
        public string Type { get; set; }

        public static SqlDbType ConvertSqlType(SqlDataType sqlDataType)
        {
            SqlDbType sqlDbType;
            switch (sqlDataType)
            {
                case SqlDataType.UserDefinedTableType:
                    sqlDbType = SqlDbType.Udt;
                    break;
                case SqlDataType.VarBinaryMax:
                    sqlDbType = SqlDbType.VarBinary;
                    break;
                case SqlDataType.NVarChar:
                    sqlDbType = SqlDbType.VarChar;
                    break;
                case SqlDataType.VarChar:
                    sqlDbType = SqlDbType.VarChar;
                    break;
                case SqlDataType.NVarCharMax:
                    sqlDbType = SqlDbType.VarChar;
                    break;
                case SqlDataType.VarBinary:
                    sqlDbType = SqlDbType.VarBinary;
                    break;
                case SqlDataType.Xml:
                    sqlDbType = SqlDbType.Xml;
                    break;
                case SqlDataType.DateTime2:
                    sqlDbType = SqlDbType.DateTime2;
                    break;
                case SqlDataType.DateTime:
                    sqlDbType = SqlDbType.DateTime;
                    break;
               
                case SqlDataType.BigInt:
                    sqlDbType = SqlDbType.BigInt;
                    break;

                case SqlDataType.Bit:
                    sqlDbType = SqlDbType.Bit;
                    break;
                case SqlDataType.TinyInt:
                    sqlDbType = SqlDbType.TinyInt;
                    break;
                case SqlDataType.Date:
                    sqlDbType = SqlDbType.Date;
                    break;
                case SqlDataType.UniqueIdentifier:
                    sqlDbType = SqlDbType.UniqueIdentifier;
                    break;
                default:
                    sqlDbType =(SqlDbType)Enum.Parse(typeof(SqlDbType), sqlDataType.ToString());
                break;
            }
            return sqlDbType;
        }

        public static Type GetNormalType(SqlDbType Sqltype)
        {
            Type type = null;
            if (Sqltype == SqlDbType.Int || Sqltype == SqlDbType.BigInt)
            {
                type = typeof(int);
            }
            if (Sqltype == SqlDbType.VarChar || Sqltype == SqlDbType.Char || Sqltype == SqlDbType.NChar || Sqltype == SqlDbType.NVarChar)
            {
                type = typeof(string);
            }
            if (Sqltype == SqlDbType.Text || Sqltype == SqlDbType.NText || Sqltype == SqlDbType.Xml)
            {
                type = typeof(string);
            }
            if (Sqltype == SqlDbType.Decimal)
            {
                 type = typeof(decimal);
            }
            if (Sqltype == SqlDbType.Float)
            {
                 type = typeof(float);
            }
            if (Sqltype == SqlDbType.VarBinary || Sqltype == SqlDbType.Image || Sqltype == SqlDbType.Binary)
            {
                type = typeof(byte[]);
            }
            if (Sqltype == SqlDbType.DateTime || Sqltype == SqlDbType.Date || Sqltype == SqlDbType.DateTime2)
            {
                type = typeof(DateTime);
            }
            if (Sqltype == SqlDbType.Bit)
            {
                type = typeof(bool);
            }
            if (Sqltype == SqlDbType.TinyInt )
            {
                type = typeof(Byte);
            }
            if (Sqltype == SqlDbType.BigInt)
            {
                type = typeof(long);
            }
            if (Sqltype == SqlDbType.UniqueIdentifier)
            {
                type = typeof(Guid);
            }
            
            return type;
        }
    }
}
